home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 2.6 KB | 107 lines | [TEXT/MPS ] |
- Program ParsePath;
-
- uses
- Files,Memory,Errors,IntEnv;
-
- const
- noError = 0;
-
- type
- longString = record
- length : integer;
- text : Ptr;
- end;
-
- var
- theError : OSErr;
- here : FSSpec;
- theInputString : longString;
- tempByte : Byte;
-
-
-
- function GetElement(theElement: StringPtr; thePathname: longString; elementIndex: integer): boolean;
- var
- elemStart, elemEnd : longint;
- begin
- elemStart := longint(thePathname.text);
- while (elementIndex > 1) and (elemStart <
- longint(thePathname.text) + thePathname.length) do begin
- if Ptr(elemStart)^ = ord(':') then
- elementIndex := elementIndex - 1;
- elemStart := elemStart + 1;
- end;
- elemEnd := elemStart;
- while (Ptr(elemEnd)^ <> ord(':')) and (elemEnd <
- longint(thePathname.text) + thePathname.length) do
- elemEnd := elemEnd + 1;
- if (elemEnd > elemStart) and (elemEnd < elemStart + 32) then begin
- BlockMove(Ptr(elemStart),Ptr(longint(theElement) + 1),elemEnd - elemStart);
- theElement^[0] := char(elemEnd - elemStart);
- GetElement := true;
- end else
- GetElement := false;
- end;
-
-
- function ParseFullPathName(VAR theResult: FSSpec; thePathname: longString) : OSErr; { Walk down thePath, returning an FSSpec }
-
- var
- theOSError : OSErr;
- theLevel : integer;
- theDInfo : CInfoPBRec;
- theVInfo : HParamBlockRec;
-
- begin
- theLevel := 2;
- ParseFullPathName := noError;
-
- theResult.parID := fsRtDirID;
-
- if GetElement(StringPtr(@theResult.name), thePathname, 1) then begin
- with theVInfo do begin
- ioVRefNum := 0;
- ioNamePtr := Pointer(@theResult.name);
- ioVolIndex := -1;
- end;
- theError := PBHGetVInfo(@theVInfo,false);
- if theError <> 0 then
- ParseFullPathName := theError
- else
- theResult.vRefNum := theVInfo.ioVRefNum;
- end;
-
- while GetElement(StringPtr(@theResult.name), thePathname, theLevel) do begin
- with theDInfo do begin
- ioFDirIndex := 0;
- ioDrDirID := theResult.parID;
- ioVRefNum := theResult.vRefNum;
- ioNamePtr := Pointer(@theResult.name);
- end;
- theError := PBGetCatInfo(@theDInfo, false);
- if theError <> 0 then
- ParseFullPathName := theError
- else
- theResult.parID := theDInfo.ioDrDirID;
- theLevel := theLevel + 1;
- end;
- end;
-
-
-
- begin
- if argC <> 2 then writeln('Form: ParseFullPathname <pathname>')
- else begin
- tempByte := Ptr(argV^[1])^;
- theInputString.length := tempByte;
- theInputString.text := Ptr(longint(argV^[1])+1);
- theError := ParseFullPathName(here,theInputString);
- if theError <> noError then
- writeln('Failed on error ',theError,'.')
- else begin
- writeln(' vRefNum: ',here.vRefNum);
- writeln(' DirID: ',here.parID);
- writeln(' Name: ',here.name);
- end;
- end;
- end.